﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CozyKxlol.Engine;
using CozyKxlol.Kxlol.Object;
using Starbound.Input;
using Microsoft.Xna.Framework;

namespace CozyKxlol.Kxlol.Scene
{
    public class HappinessGameLayer : CozyLayer
    {
        MouseEvents Mouse { get; set; }
        HappinessLiving Player { get; set; }

        Vector2 Speed { get; set; }

        public HappinessGameLayer()
        {
            Mouse = new MouseEvents();
            Mouse.ButtonClicked += OnMouseClicked;

            Speed = new Vector2(300, 300);

            Player = new HappinessLiving(@"Images\player_stop.png");
            this.AddChind(Player);
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gameTime)
        {
            Mouse.Update(gameTime);
        }

        public void OnMouseClicked(object sender, MouseButtonEventArgs msg)
        {
            if(msg.Button == MouseButton.Left)
            {
                if(Player != null)
                {
                    var pos = msg.Current.Position.ToVector2();
                    float distance = (pos - Player.Position).Length();
                    var act = CozyMoveTo.Create(distance / Speed.Length(), pos);
                    Player.RunAction(act);
                }
            }
        }
    }
}
